#include "labelinputdialog.h"

LabelInputDialog::LabelInputDialog(const QStringList &suggestions, const QString &currentText, QWidget *parent)
    : QDialog(parent)
{
    setWindowTitle("输入标签");

    comboBox = new QComboBox(this);
    comboBox->addItems(suggestions);
    comboBox->setEditable(false);

    lineEdit = new QLineEdit(this);
    lineEdit->setText(currentText);

    QPushButton *okButton = new QPushButton("确定", this);
    QPushButton *cancelButton = new QPushButton("取消", this);

    connect(okButton, &QPushButton::clicked, this, &QDialog::accept);
    connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
    connect(comboBox, &QComboBox::currentTextChanged, lineEdit, &QLineEdit::setText);

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->addWidget(comboBox);
    layout->addWidget(lineEdit);
    layout->addWidget(okButton);
    layout->addWidget(cancelButton);
}

QString LabelInputDialog::text() const {
    return lineEdit->text();
}
